package com.erp.erp_ui.Log;

import com.erp.erp_entitys.LogDB.LogDBEntity;
import com.erp.erp_servers.log.ILogDBService;
import com.erp.erp_ui.base.Base;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName LogControl
 * @Description 日志相关处理类
 * @Author songjizhen
 * @Date 2021-07-12 21:59
 * @Version 1.0
 */
@Controller
@RequestMapping(value = "logdb")
public class LogDBControl extends Base {
    @Autowired
    ILogDBService logDBService;

    /**
     * 分页查询日志
     * @param
     * @return
     */
    @RequestMapping(value = "queryByPage"  )
    @ResponseBody
    public R queryByPage(LogDBEntity logDBEntity){//
        try {
            //LogDBEntity logDBEntity=new LogDBEntity();
            List<LogDBEntity> list = logDBService.query(logDBEntity);
            return R.build(list);
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 解析今日日志,一小时内只能发起解析一次
     */
    @RequestMapping(value = "insert"  )
    @ResponseBody
    public void insert(){
        try {
            boolean tf =false;
            if(null !=this.getSession().getAttribute("log")){
                long s1=(long)this.getSession().getAttribute("log");
                int   num=(int)(System.currentTimeMillis()-s1)/(1000*60*60);
                if(num >=1){
                    tf=true;
                }
            }else{
                this.getSession().setAttribute("log",System.currentTimeMillis());
                tf=true;
            }
            if(tf){

                logDBService.insert(tf);
            }
        }catch (Exception e){
            e.printStackTrace();

        }
    }
}
